/*******************************************************************************
																				
	DESCRIPTION:  	This do file produces panel B of Figure 1 and panels A and 
					D of Figure 2.
					
*******************************************************************************/

clear all
global id_code 112

local model Full	
local year 2006
foreach vars in _ _SeqDrop_incIndiv_ {
		 	
	* Load the data
	use "${data}/003_MainWithEnsemblePred_`model'`vars'`year'.dta", clear
	
	* Put into a frame:
	frame copy default t_`model'`vars'`year'
}
		
*******************************************************************************
	* Produce kernel density plots comparing the full and basic model
******************************************************************************
	
* Combine the predictions
frame change t_Full_SeqDrop_incIndiv_2006	
	
frame change t_Full_2006
rename p_emplAft6M_0M_In p_emplAft6M_0M_In_FU
rename p_emplAft6M_6M_In p_emplAft6M_6M_In_FU


keep LopNr_PersonNr InLnr emplAft6M_0M_In p_emplAft6M_0M_In_FU p_emplAft6M_6M_In_FU startU

frlink 1:1 LopNr_PersonNr InLnr, frame(t_Full_SeqDrop_incIndiv_2006)
frget p_emplAft6M_0M_In, from(t_Full_SeqDrop_incIndiv_2006)

rename p_emplAft6M_0M_In p_emplAft6M_0M_In_BA

* Plot the distribution from the full and basic model
twoway ///
	(kdensity p_emplAft6M_0M_In_BA , fcolor(orange_red%30) lcolor(orange_red) recast(area)) ///
	(kdensity p_emplAft6M_0M_In_FU , recast(area)  fcolor(ebblue%30) lcolor(ebblue)), ///
	graphregion(color(white)) plotregion(margin(b=0 l=0))						///
	xtitle("6-Month Job-Finding Probability at Start of Spell (2006 Sample)") ytitle("Density") 			///
	xscale(titlegap(2)) yscale(titlegap(2))	xlabel(0(0.1)1) ylabel(0(1)4, angle(0) format(%9.0g)) ///
	legend(cols(2) order(2 "Baseline Model" 1 "Basic Model") region(lwidth(none))) ///
	name(distBasicFull)
	
graph export "${output}/${id_code}_Predicted6MJFR_Distribution_0M_FullvsBasic_2006_kdensity.pdf", as(pdf) replace

*******************************************************************************
 * Produce histograms using just the full model
*******************************************************************************
* Baseline histogram:
sum p_emplAft6M_0M_In_FU, detail
local mean: di %5.3f r(mean)
local var: di %5.3f r(sd)^2

corr p_emplAft6M_0M_In_FU emplAft6M_0M_In, cov
local cov: di %5.3f r(cov_12)

_pctile p_emplAft6M_0M_In_FU, percentiles(5 20 80)
di "5th pctile is `: di %5.3f `=r(r1)''"  
di "20th pctile is `: di %5.3f `=r(r2)''"
di "80th pctile is `: di %5.3f `=r(r3)''"

histogram p_emplAft6M_0M_In_FU if 2006==year(startU), ///
	frequency width(0.020) fcolor(ebblue*0.5) lcolor(ebblue) ///
	 ///
	legend(on order(/* 1 "{bf:Baseline Model, 2006}" */ ///
		- "{fontface Arial: E(F) = `mean'}" ///
		- "Var(F) = `var'" ///
		- "Cov(F, F) = `cov'" ) ///
		symxsize(*0.5) size(small) cols(1) pos(10) ring(0))			///
	graphregion(color(white)) ///
	xaxis(1 2) ///
	ytitle("Frequency", size(9pt)) ///
	xtitle("Predicted 6-Month Job-Finding Probability at Start of Spell", size(9pt)) ///
	ylabel(, angle(0) format(%9.0fc)) yscale(titlegap(2)) ///
	xlabel(0(0.2)1) xscale(titlegap(2) axis(1)) 					///
	xtitle("", axis(2)) ///
	xscale(noline axis(2)) ///
	xlabel(none, value axis(2) noticks) ///
	name(distFull0, replace)
	graph export "${output}/${id_code}_Predicted6MJFR_Distribution_0M_Full_2006_histogram.pdf", as(pdf) replace

* Plot the distribution of the 6M JFR at 0 and 6M:
twoway ///
	(kdensity p_emplAft6M_6M_In_FU, fcolor(orange_red%30) lcolor(orange_red) recast(area)) ///
	(kdensity p_emplAft6M_0M_In_FU, recast(area)  fcolor(ebblue%30) lcolor(ebblue)), ///
	graphregion(color(white)) plotregion(margin(b=0 l=0))						///
	xtitle("6-Month Job-Finding Probability (2006 Sample, Baseline Model)") ytitle("Density") 			///
	xscale(titlegap(2)) yscale(titlegap(2))	xlabel(0(0.1)1) ylabel(0(1)3, angle(0) format(%9.0g)) ///
	legend(cols(2) order(2 "At Start of Spell" 1 "6 Months into Spell") region(lwidth(none))) ///
	name(distFull06, replace)

graph export "${output}/${id_code}_Predicted6MJFR_Distribution_0Mvs6M_Full_2006_kdensity.pdf", as(pdf) replace



